package com.shen.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shen.commonutils.Result;
import com.shen.eduservice.entity.EduCourse;
import com.shen.eduservice.entity.EduTeacher;
import com.shen.eduservice.service.EduCourseService;
import com.shen.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {
    @Autowired
    EduTeacherService teacherService;
    @Autowired
    EduCourseService courseService;
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public Result getTeacherFrontList(@PathVariable("page") long page,@PathVariable("limit") long limit){

        Page<EduTeacher> pageTeacher=new Page<>(page,limit);
       Map<String,Object> map=teacherService.getTeacherFrontList(pageTeacher);
       //需要返回所有数据--

        return  Result.ok().data("data",map);
    }

    @GetMapping("getTeacherFrontInfo/{id}")
    //查询讲师的基本信息，和讲师的课程
    public  Result getTeacherFrontInfo(@PathVariable String id){
        EduTeacher teacher = teacherService.getById(id);

        QueryWrapper<EduCourse> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("teacher_id",id);
        List<EduCourse> courses = courseService.list(queryWrapper);
        return Result.ok().data("teacher",teacher).data("courseList",courses);
    }
}
